// pages/home/index/index.js
import {getList as getProductList} from "../../../service/Product";
import {getList as geNewsList} from "../../../service/News";
import Questionnaire from "../../../service/Questionnaire";
import Revisit from "../../../service/Revisit";
// import {accLess} from "../../../utils/Util";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        banner: ["/images/banner.png"],
        productList: [],
        showProductLoading: true,
        newsList: [],
        showNewsLoading: true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getProductList();
        this.getNewsList();
    },

    onShow: async function () {
        try {
            let questionnaireRes = await Questionnaire.checkComplete();
            if (!questionnaireRes) return false;
            await Revisit.checkComplete();
        } catch (e) {
            console.error(e)
        }
    },

    /*
    * 获取产品列表
    * */
    getProductList: async function () {
        try {
            let res = await getProductList({
                "page": 1,
                "per-page": 3
            })
            this.setData({
                productList: res.itemList,
                showProductLoading: false
            })
        } catch (e) {
            console.error(e)
        }
    },


    /*
    * 获取产品列表
    * */
    getNewsList: async function () {
        try {
            let res = await geNewsList({
                "page": 1,
                "per-page": 3
            })
            this.setData({
                newsList: res.itemList,
                showNewsLoading: false
            })
        } catch (e) {
            console.error(e)
        }
    },

    /*
    * 下拉刷新
    * */
    onPullDownRefresh: async function () {
        await this.getProductList();
        await this.getNewsList();
        wx.stopPullDownRefresh();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})